<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
<script>
    function formatNumber(num){
        const numStr = num.toString()
        let positiveStr = numStr
        let hasSymbol = false
        if(numStr.startsWith('-')){
            positiveStr = numStr.slice(1)
            hasSymbol = true
        }
        const decimalStr = positiveStr.split('.')[1]
        const intStr = positiveStr.split('.')[0]
        const reverseInt = intStr.split('').reverse().join('')
        let resultReverseInt = ''
        for(let i = 0;i < reverseInt.length;i++){
            if (i !== 0 && i % 3 === 0){
                resultReverseInt += ','
            }
            resultReverseInt += reverseInt[i]
        }
        let resultInt = resultReverseInt.split('').reverse().join('')
        if (hasSymbol){
            resultInt = '-' + resultInt
        }
        return resultInt + '.' + decimalStr
    }

    console.log(formatNumber(-273342213.46722))
</script>
</html>